<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html lang="en">
<head>
<%@include file="/WEB-INF/jsp/qsws/commons/head.jsp" %>
<link rel="stylesheet" type="text/css" href="resources/libs/breakingnews.css">
<link rel="stylesheet" type="text/css" href="resources/qsws/css/index.css">
<script src="resources/libs/breakingnews.js" type="text/javascript"></script>
<script src="resources/qsws/js/index.js" type="text/javascript"></script>
<script type="text/javascript">
	$(function() {
		var articleCategoryId = 1;
		var courseCategoryId = 28032;
		var pageNumber = 1;
		var pageSize = 9;
		var articleUrl = "api/aticle/articleList";
		var articleDetailUrl = "qsws/toArticleDetailPage";
		var courseUrl = "api/course/fourHotCourse";
		var courseCountUrl = "api/courseCount/findCourseCountByCourseId";
		var teacherUrl = "api/teacher/getRecommentTeacher";
		var sendedData = {
			"categoryId" : articleCategoryId,
			"pageNumber" : pageNumber,
			"pageSize" : pageSize
		};
		//滚动资讯
		$.post(articleUrl, sendedData, function(data) {
			var list = data.articleList;
			for ( var i = 0; i < list.length; i++) {
				$('.roll-info').append(
						'<li><a href="' + articleDetailUrl + '?articleId=' + list[i].id + '" class="ell">'
								+ list[i].title + '</a></li>');
			}
			$('#breakingnews2').BreakingNews({
				title : '滚动资讯',
				timer : 2000,
				effect : 'slide'
			});
		}, "json");
		//听资讯
		sendedData.pageSize = 6;
		$.post(articleUrl, sendedData, function(data) {
			var list = data.articleList;
			for ( var i = 0; i < list.length; i++) {
				$('.zixun ul').append(
						'<li><a href="javascript:;" class="ell">'
								+ list[i].title + '</a></li>');
			}
		}, "json");
		//推荐讲师
		var defaultHeaderPhoto = 'resources/qsws/img/people1.jpg';
		$.getJSON(teacherUrl,function(data){
			var list = data.recommentTeachers;
			for(var i = 0; i < list.length; i++){
				$li = $('.teachers li:first').clone();
				$li.find('a').attr('href','qsws/toTeacherDetailPage?teacherId=' + list[i].id);
				$li.find('img').attr('src',(list[i].photo?list[i].photo:defaultHeaderPhoto));
				$li.find('p').text(list[i].name);
				$li.show();
				$('.teachers ul').append($li);
			}
		});
		//热门课程
		$.getJSON(courseUrl,function(data) {
							var list = data.hotCourses;
							for ( var i = 0; i < list.length; i++) {
								var $li = $('.courses li:first').clone();
								$li.find('a').attr('href','qsws/toCourseDetailPage');
								$li.find('img').attr('src', list[i].middle_img);
								courseUrl = "api/course/getCourseCategory";
								syncAjaxPost(courseUrl, {"courseId" : list[i].id}, function(data2){
									$li.find('span').text(data2.courseCategory?data2.courseCategory.name:'暂无');
								});
								$li.find('.title').text(list[i].name);
								courseUrl = "api/course/getCourseMetadata";
								syncAjaxPost(courseUrl, {"courseId" : list[i].id}, function(data2){
									$li.find('i').text('学时：' + (data2.courseMetadata ? data2.courseMetadata.period : 0.0));
								});
								syncAjaxPost(courseCountUrl, {"courseId" : list[i].id}, function(data2){
									$li.find('b').html(data2.courseCount ? data2.courseCount.study_num : 0);
								});
								$li.show();
								$('.courses ul').append($li);
							}
						});
	});
	function syncAjaxPost(url, sendedData, fun) {
		$.ajax({
			type : "POST",
			url : url,
			data : sendedData,
			async : false,
			success : function(receiveData) {
				fun(receiveData);
			}
		});
	}
</script>
</head>
<body>
	<!-- 头部 -->
	<header class=" clearfix"> <a href="qsws/toSearchPage" class="sreach"></a>
	<h1></h1>
	<a href="" class="myData"></a> </header>
	<!-- 内容 -->
	<section>
		<div class="swiper1 swiper-container">
			<div class="swiper-wrapper">
				<div class="swiper-slide">
					<img src="resources/qsws/img/img1.jpg" alt="">
				</div>
				<div class="swiper-slide">
					<img src="resources/qsws/img/img2.jpg" alt="">
				</div>
				<div class="swiper-slide">
					<img src="resources/qsws/img/img3.jpg" alt="">
				</div>
			</div>
			<div class="swiper-pagination"></div>
		</div>
		<div class="BreakingNewsController easing clearfix" id="breakingnews2">
			<div class="bn-title l"></div>
			<ul id="abc" class="l roll-info"></ul>
		</div>
		<div class="kuang_4">
			<div class="clearfix">
				<a href="shidongzhuantiliebiao_1.html" class="color1">TPP</a> <a
					href="shidongzhuantiliebiao_2.html" class="color2">国学经典</a> <a
					href="shidongzhuantiliebiao_3.html" class="color3">和平发展</a> <a
					href="shidongzhuantiliebiao_4.html" class="color4">反腐倡廉</a>
			</div>
		</div>
		<div class="teachers">
			<div class="top clearfix">
				<h3 class="l">推荐讲师</h3>
				<a href="qsws/toTeacherListPage" class="r">更多</a>
			</div>
			<ul class="clearfix">
				<li style="display:none;"><a><img
					src="resources/qsws/img/people1.jpg" alt="">
					<p>陈向阳</p></a>
				</li>
			</ul>
		</div>
		<div class="zixun clearfix">
			<div class="top l">
				<h3 class="l">听资讯</h3>
				<a href="" class="r">更多</a>
			</div>
			<ul class="l"></ul>
			<div class="play r">
				<audio src=""></audio>
			</div>
		</div>
		<div class="courses">
			<div class="top clearfix">
				<h3 class="l">热门课程</h3>
				<a href="qsws/toHotCoursePage" class="r">更多</a>
			</div>
			<ul class="clearfix">
				<li class="l" style="display:none;"><a><img
					src="resources/qsws/img/img2.jpg"
					onerror="this.src='resources/qsws/img/img2.jpg'" alt="" /> <span>生态环境</span>
					<p class="title ell"></p></a>
					<p class="msg">
						<i></i><b></b>
					</p>
				</li>
			</ul>
		</div>
	</section>
</body>
</html>